package com.gp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gp.dao.LogDao;
import com.gp.entity.SysOperLog;
import com.gp.service.LogService;
import com.gp.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 来一杯凉咖
 * @create 2022/3/11 13:19
 */
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogDao logDao;

    /**
     * 查询日志
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<SysOperLog> getAllLogsForPage(Integer page, Integer size) {
        QueryWrapper<SysOperLog> wrapper = new QueryWrapper<>();
        PageHelper.startPage(page, size);
        List<SysOperLog> allLogsList = logDao.selectList(wrapper);
        PageInfo<SysOperLog> pageInfo = new PageInfo<>(allLogsList);
        return pageInfo;
    }

    /**
     * 删除
     * @param OperId
     * @return
     */
    @Override
    public CommonResult deleteLogById(Integer OperId) {
        int i = logDao.deleteById(OperId);
        if (i > 0) {
            return new CommonResult(200, "删除成功", null);
        } else {
            return new CommonResult(500, "删除失败", null);
        }
    }

    /**
     * 查询
     * @param page
     * @param size
     * @param title
     * @return
     */
    @Override
    public PageInfo<SysOperLog> queryLog(Integer page, Integer size, String title) {
        PageHelper.startPage(page,size);
        List<SysOperLog> logList = logDao.selectLog(title);
        PageInfo<SysOperLog> pageInfo = new PageInfo<>(logList);
        return pageInfo;
    }
}
